var ysb={}; 
layui.use(['form','layer'], function () {
    	var $ = layui.jquery;
    	var form = layui.form;
    	var layer = layui.layer;
        windowHeightFun();
        window.onresize=function(){
            windowHeightFun();
        }
   	    //验证登录
	     
	     /**
	      *  form.verify({
	        	username: [/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/, '账号格式不正确'],
	            pass: [/^[\S]{6,12}$/, '密码必须6到12位，且不能出现空格']
	        });
	      */
	 
        function windowHeightFun(){
            if($(window).height()<=800 && $(window).height()>721){
                $('body').addClass('middle').removeClass('little');
            }else if($(window).height()<=720){
                $('body').addClass('little').removeClass('middle');
            }else{
                $('body').removeClass('little').removeClass('middle');
            }
        };
        
        //监听提交
        ysb.login=function(){
    	   var userName=$("#userName").val();
           var rememberMe=$("#rememberMe").val();
           var password=$("#password").val();
            if (rememberMe){//记住密码
                localStorage.getPwd =password;
            } else {
                localStorage.getPwd = '';
            }
            $.ajax({
            	type:"POST",
            	url:"/api/sys/login",
            	data:{"userName":userName,"password":password,"rememberMe":rememberMe},
	            success:function(data){
	            	var code=data.code;
	            	var msg=data.msg;
	            	var token=data.token;
	            	var user=data.user;
	            	if(code=="0"||msg=="success"){
	            		 layer.msg("登录成功");
	            		 localStorage.getToken =token;
						 localStorage.SysUser =user;
	            		 location.href = 'index.html';
	            	}else{
	            		   layer.msg(data.msg);
	            	}
	            }
            });
            return false;
        };
        
    	/**
    	 * 获取登录用户的用户信息
    	 */
    	ysb.userInfo=function(){
    	    $.ajax({
    	    	type:"GET",
    	    	url:"/api/sys/user/info",
    	    	data:{"token":localStorage.getToken},
    	        success:function(data){
    	        	var code=data.code;
    	        	var msg=data.msg;
    	        	var userName=data.user.userName;
    	        	var realName=data.user.realName;
    	        	var email=data.user.email;
    	        	var mobile=data.user.mobile;
    	        	var roleIdList=data.user.roleIdList;
    	        	if(code=="0"&&msg=="success"&&userName!=null&&userName!=""){
    	        		localStorage.getUserName =userName;
    	        		localStorage.getRealName =realName;
    	        		localStorage.getEmail =email;
    	        		localStorage.getMobile =mobile;
    	        		localStorage.getRoleIdList =roleIdList;
    	        		location.href = 'index.html';
    	        	}	
    	        }
    	    });
    	};
        ysb.userInfo();
 });

